/* SPDX-License-Identifier: GPL-2.0 */
/*
 * Copyright (C) 2016-2019, LomboTech Co.Ltd.
 * Authors:
 *	lomboswer <lomboswer@lombotech.com>
 *
 * This program is free software; you can redistribute  it and/or modify it
 * under  the terms of  the GNU General  Public License as published by the
 * Free Software Foundation;  either version 2 of the  License, or (at your
 * option) any later version.
 */

#ifndef _LOMBO_DPU_H_
#define _LOMBO_DPU_H_

/* must be synced with enum tag_dpu_mod_t defined in csp_dpu_top.h */
enum {
	LOMBO_DPU_MOD_DC0,
	LOMBO_DPU_MOD_DC1,
	LOMBO_DPU_MOD_SE0,
	LOMBO_DPU_MOD_SE1,
	LOMBO_DPU_MOD_SE2,
	LOMBO_DPU_MOD_OVE,
	LOMBO_DPU_MOD_WB,

};

enum {
	LOMBO_DPU_CLK_REQ_RATE = 1,
	LOMBO_DPU_CLK_REAL_RATE,
	LOMBO_DPU_CLK_PARENT_RATE,
};

/* for compatible */
#define LOMBO_DPU_MOD_ROT LOMBO_DPU_MOD_SE2
#define LOMBO_DPU_MOD_DIT LOMBO_DPU_MOD_OVE

#define LOMBO_DPU_SCLK_DEF 0xEF

struct device;
struct lombo_dpu_clk;

struct lombo_dpu_clk *lombo_dpu_get_clk(struct device *dpu_top,
	struct device *mod, unsigned int dpu_mod, unsigned int sclk_id);
int lombo_dpu_put_clk(struct lombo_dpu_clk **clk);

unsigned long lombo_dpu_clk_get_rate(struct lombo_dpu_clk *clk, int which);
int lombo_dpu_clk_set_rate_g(struct lombo_dpu_clk *clk,
	unsigned long rate, int sync);

int lombo_dpu_clk_prepare_enable(struct lombo_dpu_clk *clk, int sw);
int lombo_dpu_clk_disable_unprepare(struct lombo_dpu_clk *clk);

/**
 * get a enabled timer clock
 * @req_rate: requried-rate.
 * @real_rate: real rate returned.
 */
struct lombo_dpu_clk *lombo_dpu_get_enable_tclk(struct device *dpu_top,
	unsigned long req_rate, unsigned long *real_rate);

/* get clk by def-sclk */
static inline struct lombo_dpu_clk *lombo_dpu_get_clk_def(
	struct device *dpu_top, struct device *mod, unsigned int dpu_mod)
{
	return lombo_dpu_get_clk(dpu_top, mod, dpu_mod, LOMBO_DPU_SCLK_DEF);
}

int lombo_dpu_set_wb_mode(unsigned int mode);

#define lombo_dpu_clk_get_parent_rate(clk)	\
		lombo_dpu_clk_get_rate(clk, LOMBO_DPU_CLK_PARENT_RATE)
#define lombo_dpu_clk_get_req_rate(clk)	\
		lombo_dpu_clk_get_rate(clk, LOMBO_DPU_CLK_REQ_RATE)
#define lombo_dpu_clk_get_real_rate(clk)	\
		lombo_dpu_clk_get_rate(clk, LOMBO_DPU_CLK_REAL_RATE)

#define lombo_dpu_clk_set_rate(clk, rate)	\
		lombo_dpu_clk_set_rate_g(clk, rate, 0)
#define lombo_dpu_clk_set_rate_sync(clk, rate)	\
		lombo_dpu_clk_set_rate_g(clk, rate, 1)

#endif /* #ifndef _LOMBO_DPU_H_ */
